// 1.引入vue
import Vue from "vue"
import Vuex from "vuex"
Vue.use(Vuex)
// 2.暴露store
export default new Vuex.Store({
    strict: true,
    state: {
        name: '小蓝',
        age: 18,
        gender: "女",
        count: 0,
        list: [1, 2, 3, 4, 5, 6, 7, 8, 9],
        student: {
           
            name: '小青',
            age:18,
            school: {
                name:'吉山幼儿园',
                address: {
                    city: '广州',
                    street: '珠吉路',
                    detail:'珠吉路58号222教室'
                }
            }
            
        }
    },
    mutations: {
        addCount(state, data) {
            // 每次点击的时候，加666
            state.count+=Number(data)
        }
    },
    actions: {
        // data是dispatch传过来的
        asyncAddcount(store,data) {
            setTimeout(() => {
                store.commit('addCount',data)
            }, 1000);
        }
    },
    getters: {
        filterList: state => state.list.filter(item => item > 2),
        addrDetail: state=>state.student.school.address.detail
    }
})
